package com.example.expresscabinet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.expresscabinet.dao.cabinetMapper;
import com.example.expresscabinet.dao.getexpressMapper;
import com.example.expresscabinet.model.cabinet;
import com.example.expresscabinet.model.getexpress;
import com.example.expresscabinet.service.ICabinetService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class cabinetServiceImpl extends ServiceImpl<cabinetMapper, cabinet> implements ICabinetService {

    @Resource
    cabinetMapper cabinetMapper;

    @Resource
    getexpressMapper getexpressMapper;

    //查询空柜子列表
    @Override
    public Page<cabinet> emptyCabinet(Integer pageNum, Integer pageSize){
        QueryWrapper<cabinet> wrapper=new QueryWrapper<>();
        wrapper.eq("states","空闲");
        Page<cabinet> res= cabinetMapper.selectPage(new Page<>(pageNum,pageSize),wrapper);
        return res;
    }

    @Override
    public void takeEmptyCabinet(int num){
        QueryWrapper<cabinet> wrapper=new QueryWrapper<>();
        wrapper.eq("num",num);
        cabinet cabinet=new cabinet();
        cabinet.setStates("空闲");
        cabinetMapper.update(cabinet,wrapper);
    }


    @Override
    public void takeEmptyCabinetByCode(String code){
        QueryWrapper<getexpress> wrapper=new QueryWrapper<>();
        wrapper.eq("code",code);
        getexpress ge=getexpressMapper.selectOne(wrapper);
        int num=ge.getNum();
        QueryWrapper<cabinet> wrapper1=new QueryWrapper<>();
        wrapper1.eq("num",num);
        cabinet cabinet=new cabinet();
        cabinet.setStates("空闲");
        cabinetMapper.update(cabinet,wrapper1);
    }


    @Override
    public void takeOccupyCabinet(int num){
        QueryWrapper<cabinet> wrapper=new QueryWrapper<>();
        wrapper.eq("num",num);
        cabinet cabinet=new cabinet();
        cabinet.setStates("使用中");
        cabinetMapper.update(cabinet,wrapper);
    }
}
